package com.junlong0716.enjoylearning.adapter

import android.annotation.SuppressLint
import android.view.View
import android.widget.TextView
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.htxcsoft.corelibrary.glide.GlideUtils
import com.junlong0716.enjoylearning.R
import com.junlong0716.enjoylearning.constant.NetConstant
import com.junlong0716.enjoylearning.entity.ChannelMultipleItemEntity
import com.junlong0716.enjoylearning.entity.CollectionEntity
import java.text.SimpleDateFormat

/**
 *@author: 巴黎没有摩天轮Li
 *@description:
 *@date: Created in 上午10:48 2018/6/24
 *@modified by:
 */
class CollectionAdapter(data:ArrayList<CollectionEntity>): BaseMultiItemQuickAdapter<CollectionEntity, BaseViewHolder>(data) {
    init {
        addItemType(CollectionEntity.ITEM_TYPE_VIDEO, R.layout.child_item_find_commend_video_layout)
        addItemType(CollectionEntity.ITEM_TYPE_AUDIO, R.layout.child_item_find_commend_audio_layout)
        addItemType(CollectionEntity.ITEM_TYPE_DOCUMENT, R.layout.child_item_find_commend_document_layout)
    }

    @SuppressLint("SimpleDateFormat")
    override fun convert(helper: BaseViewHolder?, item: CollectionEntity?) {
        when (helper!!.itemViewType) {
            ChannelMultipleItemEntity.ITEM_TYPE_VIDEO -> {
                GlideUtils.showImageFade(mContext, NetConstant.REQUEST_SOURCE +item!!.coverImg, helper.getView(R.id.riv_video_img))
                helper.setText(R.id.tv_topic_name, item.knowledgeTitle)
                helper.setText(R.id.tv_topic_description,TimeUtils.millis2String(item.createDate, SimpleDateFormat("MM-dd")))
            }
            ChannelMultipleItemEntity.ITEM_TYPE_AUDIO -> {
                GlideUtils.showImage(mContext, NetConstant.REQUEST_SOURCE + item!!.coverImg, helper.getView(R.id.civ_audio))
                helper.setText(R.id.tv_topic_name, item.knowledgeTitle)
                //helper.setText(R.id.tv_topic_description,item.authorName+"|"+ TimeUtils.millis2String(item.createDate).substring(5,10))
                helper.setText(R.id.tv_topic_description,TimeUtils.millis2String(item.createDate, SimpleDateFormat("MM-dd")))

            }
            ChannelMultipleItemEntity.ITEM_TYPE_DOCUMENT -> {
                helper.setText(R.id.tv_title, item!!.knowledgeTitle)
                helper.setText(R.id.tv_content, item.knowledgeContent)
                //helper.setText(R.id.tv_writer, item.authorName)
                helper.getView<TextView>(R.id.tv_writer).visibility = View.GONE
                helper.setText(R.id.tv_date,TimeUtils.millis2String(item.createDate, SimpleDateFormat("MM-dd")))
            }
        }
    }
}